package stack_queue;

import java.util.Stack;

/**
 * 用栈实现队列
 */
class MyQueue {

    private Stack<Integer> st1;
    private Stack<Integer> st2;

    public MyQueue() {
        st1 = new Stack<>();
        st2 = new Stack<>();
    }
    
    public void push(int x) {
        st1.push(x);
    }
    
    public int pop() {
        if(empty()){
            return -1;
        }
        if(st2.empty()){
            while(!st1.empty()){
                int temp = st1.pop();
                st2.push(temp);
            }
        }
        return st2.pop();
    }
    
    public int peek() {
        if(empty()){
            return -1;
        }
        while(!st1.empty()){
            int temp = st1.pop();
            st2.push(temp);
        }
        return st2.peek();
    }
    
    public boolean empty() {
        if(st1.empty() && st2.empty()){
            return true;
        }
        return false;
    }
}